using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using ScreenTest.Constants;
using GameStateManager;

namespace ScreenTest.Players
{
    class Hud
    {
        Player player;
        Texture2D hud;
        const int HUD_SIZE = 64;
        SpriteFont hudFont;

        public Hud(Player player, ContentManager content)
        {
            this.player = player;

            if (player.ID == 0)
            {
                hud = content.Load<Texture2D>(@"Content\hud_player1");
            }
            else
            {
                hud = content.Load<Texture2D>(@"Content\hud_player2");
            }

            hudFont = content.Load<SpriteFont>(@"Fonts\HudFont");
        }

        /// <summary>
        /// We may have animated sprites some day, so might as well
        /// pass in the GameTime object.
        /// </summary>
        /// <param name="gameTime"></param>
        public void Update(GameTime gameTime)
        {
            
        }

        public void Draw(GraphicsDevice device, SpriteBatch spriteBatch)
        {
            Viewport viewport = device.Viewport;
            Rectangle fullscreen = ScreenManager.CalculateTitleSafeArea(viewport);
            Vector2 position;

            if (player.ID == 0)
            {
                position = new Vector2(fullscreen.X, fullscreen.Height - HUD_SIZE);
            }
            else
            {
                position = new Vector2(fullscreen.Width - HUD_SIZE, fullscreen.Height - HUD_SIZE);
            }

            spriteBatch.Draw(hud, position, Color.White);

            //Draw the player information
            int currentWeapon = player.CurrentWeapon;
            int currentWeaponAmmoCount;

            if (currentWeapon == GameConstants.WEAPON_NORMAL)
            {
                currentWeaponAmmoCount = -1;
            }
            else
            {
                currentWeaponAmmoCount = player.Rockets;
            }

            if (player.ID == 0)
            {
                spriteBatch.DrawString(hudFont, currentWeaponAmmoCount.ToString(), position + new Vector2(8, 40), Color.White);
            }
            else
            {
                spriteBatch.DrawString(hudFont, currentWeaponAmmoCount.ToString(), position + new Vector2(40, 40), Color.White);
            }
            
        }
    }
}
